﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using tactics.Abilities;
using tactics.Interfaces;

namespace tactics.Commands
{
    class ApplyAbilityToUnitCommand : BaseCommand
    {
        Ability ability;
        Unit unitFrom;
        Unit unitTo;

        public ApplyAbilityToUnitCommand(Ability abilityIn, Unit unitFromIn, Unit unitToIn)
        {
            ability = abilityIn;
            unitFrom = unitFromIn;
            unitTo = unitToIn;

            Finished = false;
        }

        public override void Execute()
        {
            ability.UseAbility(unitTo);

            TacticsEngine.Instance.Game.TurnManager.UnitTurn = unitFrom;
            TacticsEngine.Instance.Game.TurnManager.AbilityUsed = true;
            unitFrom.Acted = true;

            if (TacticsEngine.Instance.Game.TurnManager.UnitMoved)
                TacticsEngine.Instance.Game.TurnManager.AdvanceTurn();

            TacticsEngine.Instance.Game.UpdateMiniPanels();

            TacticsEngine.Instance.Game.TurnManager.CheckForWin();

            Finished = true;
        }
    }
}
